<?php
class Chome extends CI_Controller{
    public function index()
    {
        $this->load->model('news_model','news');
        $this->load->library('pagination');
        $per_page = 2;
        $data['title'] = 'NoteNews - Những tin tức đáng chú ý';
        $this->load->view('header',$data);
        $config['base_url'] = base_url().'page';
        $config['total_rows'] = $this->news->get_count_news();
        $config['uri_segment'] = 4;
        $category_id = $this->uri->segment(2);
        if(!$category_id)
            $category_id = 10;
        $page = $this->uri->segment(4);
        if($page == false)
            $page = 1;
        $offset = ($page - 1)*$per_page;
        $data['content'] = $this->news->get_news($per_page,$offset);
        $config['per_page'] = $per_page; 
        $this->pagination->initialize($config); 
        $data['pagination'] = $this->pagination->create_links();
        $data['category'] = $this->news->get_list_category();
        $data['category_id'] = $category_id;
        $this->load->view('chome',$data);
        $this->load->view('footer'); 
    }
}
?>